/*
 * $Id: isbnlookup.h 27 2010-12-03 20:29:45Z vext01 $
 *
 * Copyright (c) 2010, Edd Barrett <vext01@gmail.com>
 * 
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#ifndef _ISBNLOOKUP_H_
#define _ISBNLOOKUP_H_

#ifdef __OpenBSD__
#include <sys/tree.h>
#else
#include "../contrib/tree.h"
#endif

#include "../config.h"

#define ISBNLOOKUP_VERSION	"0.1"
#define NULL_XCHAR		(xmlChar) 0

/* shortcut for casting to (xmlChar *) */
#define XC(s)			(xmlChar *) s

#define ISBN_CONFIG_FILE	".isbnlookuprc"

struct isbn_field {
	RB_ENTRY(isbn_field)	entry;
	xmlChar			*key;
	xmlChar			*val;
};

struct isbn_book {
	RB_HEAD(isbn_fields_t, isbn_field) fields;
	RB_ENTRY(isbn_book)	entry;
	xmlChar			*id;
};

struct isbn_query {
	RB_HEAD(isbn_books_t, isbn_book) books;
	int		num_books;
};

void			isbn_free_book(struct isbn_book *bk);
void			isbn_free_query(struct isbn_query *q);
int			isbn_field_cmp(struct isbn_field *e1, struct isbn_field *e2);
int			isbn_book_cmp(struct isbn_book *e1, struct isbn_book *e2);
void			isbn_add_book(struct isbn_query *q, struct isbn_book *bk);
struct isbn_query	*isbn_new_query();
struct isbn_book	*isbn_new_book();
struct isbn_query	*isbn_parse_response(struct isbn_query *q,
			    struct isbn_book *bk, xmlNode *n);

struct isbn_field	*isbn_get_field(struct isbn_book *bk, xmlChar *f);

#endif
